package com.shanzmoo.core.domain.pay;

import com.shanzmoo.db.trade.entity.PayOrderEntity;
import com.shanzmoo.base.util.BillNoUtils;
import com.shanzmoo.base.util.MoneyUtils;
import lombok.*;

import java.io.Serializable;

/**
 * 订单支付信息
 * @author: Gzhao 2020/12/10
 */
@Data
@Builder
@NoArgsConstructor
@AllArgsConstructor(access = AccessLevel.PRIVATE)
public class AliPayOrdeTradeDto implements Serializable {

    private static final long serialVersionUID = 1758L;

    /**
     * 商户订单号。64 个字符以内的大小，可包含字母、数字、下划线。
     */
    private String outTradeNo;

    /**
     * 支付场景，条码支付，取值：bar_code
     */
    private String scene;

    /**
     * 支付授权码
     */
    private String authCode;

    /**
     * 订单标题，不可使用特殊字符，如 /，=，& 等
     */
    private String subject;

    /**
     * 	订单总金额，单位为元，精确到小数点后两位，取值范围为 [0.01,100000000]，金额不能为 0
     */
    private String totalAmount;

    /**
     * 	门店id
     */
    private String storeId;

    public static AliPayOrdeTradeDto create(PayOrderEntity payOrderEntity, String authCode) {
        return AliPayOrdeTradeDto.builder()
                .outTradeNo(BillNoUtils.generatePayNo())
                .scene("bar_code")
                .authCode(authCode)
                .subject(payOrderEntity.getBody())
                .totalAmount(MoneyUtils.dealWithTotalAmonut(payOrderEntity.getTotalFee()))
                .storeId(String.valueOf(payOrderEntity.getOutletId()))
                .build();
    }
}
